<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>POS定时下单</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="./News/layui/css/layui.css"  media="all">
  <style>
      
      .ahk{
          
            display: inline-block;
            margin: 0px 0px 5px 5px;
            padding: 4px 8px;
            font-size: 14px;
            outline: none;
            text-align: center;
            width: 50px;
            line-height: 24px;
            cursor: pointer;
            color: #ccc;
            border: solid 1px #ccc;
      }
      
      .ahks{
           display: inline-block;
            margin: 0px 0px 5px 5px;
            padding: 4px 8px;
            font-size: 14px;
            outline: none;
            text-align: center;
            width: 50px;
            line-height: 24px;
            cursor: pointer;
          color: #fff;
          background: red;
      }
      .layui-form input[type=checkbox], .layui-form input[type=radio], .layui-form select {
    display: unset;
    width: 20px;
    height: 20px;
}
      
  </style>
</head>
<body>
 
<div style="width:95%; padding:10px">
    
         
 
                  
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
      <legend>POS定时下单</legend>
    </fieldset>
     
    <form class="layui-form"  id="info">
        
      <div class="layui-form-item">
        <label class="layui-form-label">总订单数</label>
        <div class="layui-input-block">
          <input type="text" name="dnum"   id="dnum" placeholder="请输入总订单数" class="layui-input">
        </div>
      </div>
      
      
      <div class="layui-form-item">
        <div class="layui-inline">
          <label class="layui-form-label">下单时间</label>
          <div class="layui-input-inline" style="width: 160px;">
            <input type="text" name="date"  id="date" lay-verify="date" placeholder="yyyy-MM-dd HH:mm:ss"  class="layui-input">
          </div>
          <div class="layui-form-mid">-</div>
          <div class="layui-input-inline" style="width: 160px;">
            <input type="text" name="date1s" id="date1s" lay-verify="date" placeholder="yyyy-MM-dd HH:mm:ss"  class="layui-input">
          </div>
        </div>
      </div>
      
      
 
      
      

      
      <div class="layui-form-item">
        <label class="layui-form-label">商家</label>
        <div class="layui-input-block" style="height:180px;overflow-y: auto;  ">
                       
              <table cellspacing="0" cellpadding="0" border="0" class="layui-table">
              
                	
                	
    
                	<?php foreach ($mall_list as $k => $v): ?>
                
                		<tr>
                			<td>
                				 
                			     <span><?=$v['name']?></span>
                			 
                			</td>
                			<td >
                				 
                				产品数量:	<span><?=$v['num']['num']?></span>
                	 
                			</td>
                			<td>
                 
                			   <span class="base">
                			   
                			   <a class="ahk"  data-id="<?=$v['user_id']?>"  lay-filter="checkResultCode" > 选择 </a>
                			   
                			   </span>
                			   
                			   
                			</td>
                		</tr>
                
                	<?php endforeach; ?>
                	
            
                	 
                	
                </table>
        </div>
      </div>

      
      
      
      <div class="layui-form-item">
        <div class="layui-inline">
          <label class="layui-form-label">间隔时间</label>
          <div class="layui-input-inline" style="width: 100px;">
            <input type="text" name="time" placeholder="分" autocomplete="off" class="layui-input">
          </div>
          <div class="layui-form-mid">-</div>
          <div class="layui-input-inline" style="width: 100px;">
            <input type="text" name="time2" placeholder="分" autocomplete="off" class="layui-input">
          </div>
        </div>
      </div>
      
 
      
     
    <div class="layui-form-item"  style="display:none"  id="goods_tpl">
        <label class="layui-form-label">卖家产品</label>
        <div class="layui-input-block" style="height:260px;overflow-y: auto;  ">
                       
              <table cellspacing="0" cellpadding="0" border="0" class="layui-table" id="tpl">
              
                	  
                	
                </table>
        </div>
      </div>
      
      
      
      
      
      <input type="hidden"  name="seller_id"  id="seller_id" >
    
      
      
     
      <div class="layui-form-item">
        <div class="layui-input-block">
          <button type="button" class="layui-btn"  id="save"  >立即提交</button>
   
        </div>
      </div>
    </form>
     
 
    
    
    
 </div>
 
<script  src="./jquery/jquery.js"  crossorigin="anonymous"></script>
<script src="./News/layui/layui.js" charset="utf-8"></script>
 
<script>
layui.use(['form', 'layedit', 'laydate'], function(){
  var form = layui.form
  ,layer = layui.layer
  ,layedit = layui.layedit
  ,laydate = layui.laydate;
  
  //日期
  laydate.render({
     elem: '#date'
    ,type: 'datetime'
    ,format: 'yyyy-MM-dd HH:mm:ss'  
  });
  laydate.render({
    elem: '#date1'
  });
  
 
 laydate.render({
    elem: '#date1s'
    ,type: 'datetime'
    ,format: 'yyyy-MM-dd HH:mm:ss'  
  });
 
  
 
  
});


$(document).ready(function(){
    
    
   
   $(".ahk").click(function(){
       
       
          var index = layer.load(0, {shade: false});
          
          
          
          $(".ahks").attr("class","ahk");
          $(this).attr("class","ahks");
          
          
          $("#seller_id").val($(this).attr('data-id'));
           
           $.ajax({
              type: 'POST',
              url: 'data.php',  
              data: {id:$(this).attr('data-id')},
              dataType: 'json',
              success: function(res) {
                  
                  if(res.error == 0){
                     
                     
                     $("#goods_tpl").show();
                     
                     layer.close(index);
                     
                      var data = res.list;
                      
                       $("#tpl").empty();
                        
                        data.forEach(user => {
                            
                            var html = "<tr><td width='50%'><p style='color:#000;font-size:12px'>"+user.name+"</p><p style='color:red;font-size:12px'>"+user.unit_price+"</p></td>";
                            
                            html+= "<td width='30%'><img style='width:40px; height:40px' src='"+user.images+"'></td>";
                            
                            html+="	<td width='20%'><input type='checkbox'  class='goods_id' name='goods_id[]'  value= '"+user.id+"'   data-id='"+user.id+"'   title='下单'></td></tr>";
                             
                 
                            
                            $("#tpl").append(html);
                        });
 	
                			
                      
                  }
              },
              error: function() {
                
              }
           });
       
    })    
    
 
 
         $(document).on('click', '.goods_id', function() {
           
              var num = $('input[type="checkbox"]').is(':checked').length;
              
        });
        
        
        $("#save").click(function(){
            
            
            if (!$('input[type="checkbox"]').is(':checked')) {
                 
                 layer.msg('必须选择需要下单的产品');
                 
                  return false;
            }  
            
            
            if($("#dnum").val() ==''){
                
                layer.msg('总单数不能小于1单');
                
                 return false;
            }
            
            if($("#time2").val() ==''  || $("#time").val() =='' ){
                
                layer.msg('间隔时间不能为空');
                
                 return false;
            }
            
            
            
            if($("#date").val() == ''){
                
                layer.msg('开始时间不能为空');
                 return false;
            }
             if($("#date1s").val() == ''){
                
                layer.msg('结束时间不能为空');
                 return false;
            }
            
            
            
              var data = $("#info").serialize();
              $.ajax({
                  type: 'POST',
                  url: 'pos.php',  
                  data: data,
                  dataType: 'json',
                  success: function(res) {
                      
                      
                      if(res.error  == 0){
                          
                          alert(res.msg);
                          
                          window.location.reload();
                       
                      } else {
                          
                           layer.msg(res.msg);
                      }
                      
                  },
                  error: function() {
                    
                  }
               });
           
        })
     
     
})


</script>

</body>
</html>